import { fileURLToPath, URL } from 'url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ViteComponents from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
// import * as path from 'path'
// import electron from 'vite-plugin-electron'
// import electronRenderer from 'vite-plugin-electron/renderer'
// import polyfillExports from 'vite-plugin-electron/polyfill-exports'

export default defineConfig({
  base: './',
  plugins: [
    vue(),
    ViteComponents({
      resolvers: [AntDesignVueResolver()],
    }),
    // electron({
    //   main: {
    //     entry: 'electron/main.js',
    //   },
    //   preload: {
    //     input: path.join(__dirname, './electron/preload.js'),
    //   },
    // }),
    // electronRenderer(),
    // polyfillExports(),
  ],
  server: {
    host: '0.0.0.0',
    port: 8284,
    open: false,
    hmr: true,
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  build: {
    assetsDir: 'static',
    assetsInlineLimit: 1024 * 1000,
    cssCodeSplit: true,
    emptyOutDir: false,
    // chunk 大小警告的限制
    chunkSizeWarningLimit: 100,
    rollupOptions: {
      output: {
        dir: 'dist',
      },
    },
  },
})
